/*
 * Copyright rgil2010
 * All rights reserved
 */

package com.totoBD.jdbc;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;


/**
 *
 * @author user
 */
public class DbConnectionSingleton {


    private  DbConnectionSingleton() throws Exception
    {
        Class.forName("com.mysql.jdbc.Driver");
        this._strUser_ = "none";
    }

    public static synchronized DbConnectionSingleton getSingletonObject() throws Exception {
		if (_singletonObject_ == null) {
			_singletonObject_ = new DbConnectionSingleton();
		}
		return _singletonObject_;
	}

    @Override
    public Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }

    public String getUser()
    {
        return this._strUser_;
    }

    public void connect(
            String strUrl,
            String strUser,
            String strPassword) throws Exception
    {
        this._strUser_ = strUser;
        _con_ = (Connection) DriverManager.getConnection(
                _url_,
                strUser,
                strPassword);
        _stmt_ =    (Statement) _con_.createStatement();
        
    }
    public void disconnect() throws Exception{
        _con_.close();
        this._strUser_ = "none";
    }


    public void executeUpdate(String strCommand) throws Exception
    {
        this._stmt_.executeUpdate(strCommand);
    }

    private static DbConnectionSingleton _singletonObject_;

    private Statement _stmt_;
    private String _url_ = "jdbc:mysql://localhost:3306/mysql";
    private Connection _con_;
    private String _strUser_;
}
